import type { FieldRule } from 'vant'
// 手机号校验规则
const mobileRule: FieldRule[] = [
  {
    required: true,
    message: '手机号不能为空',
    trigger: ['onChange', 'onBlur']
  },
  {
    pattern: /^1[3-9]\d{9}$/,
    message: '手机号格式不正确',
    trigger: ['onChange', 'onBlur']
  }
]
// 密码的校验规则
const passwordRule: FieldRule[] = [
  {
    required: true,
    message: '密码不能为空',
    trigger: ['onChange', 'onBlur']
  },
  {
    pattern: /^\w{8,16}$/,
    message: '密码格式在8-16个字符',
    trigger: ['onChange', 'onBlur']
  }
]
// 验证码的规则
const codeRule: FieldRule[] = [
  {
    required: true,
    message: '验证码不能为空',
    trigger: ['onChange', 'onBlur']
  },
  {
    pattern: /^\d{6}$/,
    message: '请输入六位验证码',
    trigger: ['onChange', 'onBlur']
  }
]
// 中文姓名的校验规则
const nameRule: FieldRule[] = [
  {
    required: true,
    message: '姓名不能为空'
  },
  {
    pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    message: '请输入正确的中文姓名'
  }
]
// 身份证号的校验规则
const idCardRule: FieldRule[] = [
  {
    required: true,
    message: '身份证不能为空'
  },
  {
    pattern:
      /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '请输入正确的身份证号'
  }
]
export { mobileRule, passwordRule, codeRule, nameRule, idCardRule }
